﻿namespace com.stifel.BranchMgmt
{
    using System.Linq;

    using com.stifel.BranchMgmtDao;
    using com.stifel.Extensions.SymbolExtensions;
    using com.stifel.SharePoint;

    using Microsoft.SharePoint;

    using CustomObject = com.stifel.BranchMgmtDao.StifelBranchVendor;

    public class StifelBranchVendor_Definition : StifelBaseDefinition
    {
        #region Constructors

        public StifelBranchVendor_Definition( SPFeatureReceiverProperties properties )
            : base(properties)
        {
        }

        ~StifelBranchVendor_Definition( )
        {
            Dispose( false );
        }

        #endregion Constructors

        #region Methods

        public override void Create( )
        {
            base.Create( );
            CreateContentType( getContentTypeDefn( ) );
            CreateList( getListDefn( ) );
        }

        public override void Delete( )
        {
            base.Delete( );
            DeleteList( getListDefn( ), false );
            DeleteContentType( getContentTypeDefn( ) );
        }

        ContentTypeDefn getContentTypeDefn( )
        {
            CustomObject c = null;
            return new ContentTypeDefn
            {
                Name = Item.GetContentTypeName<CustomObject>( ),
                ContentTypeId = Item.GetContentTypeId<CustomObject>( ),
                WebLevel = true,
                Group = "Stifel",
                Description = "Describes a branch vendor.",
                Fields = new FieldDefn[ ] {
                    new FieldDefn{
                        Name=Item.GetColumnName<CustomObject>(c.GetPropertySymbol(a=>a.BranchLookupId)),
                        Required=true
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<CustomObject>(c.GetPropertySymbol(a=>a.VendorContact)),
                        Required=true
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<CustomObject>(c.GetPropertySymbol(a=>a.VendorCompany)),
                        Required=true
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<CustomObject>(c.GetPropertySymbol(a=>a.VendorAddress))
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<CustomObject>(c.GetPropertySymbol(a=>a.VendorCity))
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<CustomObject>(c.GetPropertySymbol(a=>a.USStatesLookupId))
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<CustomObject>(c.GetPropertySymbol(a=>a.VendorZipcode))
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<CustomObject>(c.GetPropertySymbol(a=>a.VendorTelephone))
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<CustomObject>(c.GetPropertySymbol(a=>a.VendorFax))
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<CustomObject>(c.GetPropertySymbol(a=>a.VendorEmail))
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<CustomObject>(c.GetPropertySymbol(a=>a.VendorWebSite))
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<CustomObject>(c.GetPropertySymbol(a=>a.Insurance))
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<CustomObject>(c.GetPropertySymbol(a=>a.VendorNote))
                    },
                }.Distinct( ).ToList( )
            };
        }

        ListDefn getListDefn( )
        {
            return new ListDefn
            {
                RootFolderName = StifelBranchVendorDao.ListName,
                Title = "Stifel Branch Vendors",
                Description = "Contains branch vendors.",
                ContentTypes = new string[ ] {
                    Item.GetContentTypeName<CustomObject>()
                }.ToList( )
            };
        }

        #endregion Methods
    }
}